package com.jsd2412.backend.mealGroups.controller;

import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.mealGroups.pojo.dto.MealGroupQueryParam;
import com.jsd2412.backend.mealGroups.pojo.dto.MealGroupsSaveParam;
import com.jsd2412.backend.mealGroups.pojo.vo.MealGroupsVO;
import com.jsd2412.backend.mealGroups.service.MealGroupsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/mealsGroup")
public class MealGroupsController {
    @Autowired
    private MealGroupsService mealsService;

    @GetMapping("/select")
    public JsonResult selectMealGroups(MealGroupQueryParam mealsQueryParam) {
        log.debug("查询膳食分组参数:{}", mealsQueryParam);
        List<MealGroupsVO> list = mealsService.selectMeals(mealsQueryParam);
        log.debug("查询膳食分组业务:{}", list);
        return JsonResult.ok(list);
    }


    @PostMapping("/save")
    public JsonResult saveMealGroups(MealGroupsSaveParam mealGroupsSaveParam) {
        log.debug("膳食分组保存上送参数为{}", mealGroupsSaveParam);
        mealsService.saveMeals(mealGroupsSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteMealGroups(@PathVariable Long id) {
        log.debug("膳食分组删除上送参数为{}",id);
        mealsService.deleteMeals(id);
        return JsonResult.ok();
    }

}
